package com.bosssoft.boss_exam_db.service.busines.impl;

import com.bosssoft.boss_exam_db.entity.ExamExamPaper;
import com.bosssoft.boss_exam_db.mapper.ExamExamPaperMapper;
import com.bosssoft.boss_exam_db.service.base.impl.BaseServiceImpl;
import com.bosssoft.boss_exam_db.service.busines.ExamExamPaperService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
@Slf4j
public class ExamExamPaperServiceImpl extends BaseServiceImpl<ExamExamPaper> implements ExamExamPaperService {

    //注入ExamExamPaperMapper
    @Autowired
    private ExamExamPaperMapper examExamPaperMapper;


    /***
     * @Author lys(cherish)
     * @Phone 17720799636
     * @Date  2019/4/8
     * @Description 插入试卷
     * @Param [examExamPaper] 试卷
     * @Return int
     * @Exception
     * @since JDK 1.8
     **/
    @Override
    public int insertExamExamPaper(ExamExamPaper examExamPaper) {
        return examExamPaperMapper.insertSelective(examExamPaper);
    }

    /***
     * @Author lys(cherish)
     * @Phone 17720799636
     * @Date  2019/4/8
     * @Description 根据试卷ID查询试卷
     * @Param [id] 试卷ID
     * @Return java.util.List<com.bosssoft.boss_exam_db.entity.ExamExamPaper>
     * @Exception
     * @since JDK 1.8
     **/
    @Override
    public List<ExamExamPaper> queryExamPaperByExamId(String id) {
        Example example = new Example(ExamExamPaper.class);
        Example.Criteria criteria = example.createCriteria();
        if(!StringUtils.isEmpty(id)){
            criteria.andEqualTo("examId",id);
        }
        criteria.andEqualTo("deleted",false);
        List<ExamExamPaper> examExamPapers = examExamPaperMapper.selectByExample(example);
        return examExamPapers;
    }

    /***
     * @Author lys(cherish)
     * @Phone 17720799636
     * @Date  2019/4/8
     * @Description 查询考试和试卷
     * @Param [examId, examPaperId] 考试ID、试卷ID
     * @Return java.util.List<com.bosssoft.boss_exam_db.entity.ExamExamPaper>
     * @Exception
     * @since JDK 1.8
     **/
    @Override
    public List<ExamExamPaper> queryByExamIdAndExamPaper(String examId, String examPaperId) {
        Example example = new Example(ExamExamPaper.class);
        Example.Criteria criteria = example.createCriteria();
        if(StringUtils.isEmpty(examId)|| StringUtils.isEmpty(examPaperId)){
            return null;
        }
        criteria.andEqualTo("examId",examId)
                .andEqualTo("examPaperId",examPaperId)
                .andEqualTo("deleted",false);
        List<ExamExamPaper> examExamPapers = this.examExamPaperMapper.selectByExample(example);
        return examExamPapers;
    }

}
